<?php /** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection PhpMissingDocCommentInspection */

declare(strict_types=1);

namespace DreamCat\ObjectValidTest\Cases;

use DreamCat\ObjectValid\Annotation\NumberScope;
use DreamCat\ObjectValid\Base\ValidAnnoInterface;
use DreamCat\ObjectValid\Utils\AnnotationUtils;
use DreamCat\ObjectValid\Utils\ReflectionUtils;
use DreamCat\ObjectValidTest\Helper\DemoPojo;
use JetBrains\PhpStorm\Pure;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use Reflector;

/**
 * 杂项测试
 * @author vijay
 */
class UtilsTest extends TestCase
{
    public function testGetAttrObj()
    {
        $ref = new ReflectionProperty(DemoPojo::class, "value");
        $o = AnnotationUtils::getAttrObj($ref, ValidAnnoInterface::class);
        self::assertEquals(NumberScope::class, get_class($o));

        $o = AnnotationUtils::getAttrObj($ref, Pure::class);
        self::assertNull($o);
    }

    public function testRefDesc()
    {
        $o = new class() implements Reflector {
            public function getName()
            {
                return "ooeejj";
            }
            public static function export()
            {
            }
            public function __toString()
            {
                return "";
            }
        };
        self::assertEquals("ooeejj", ReflectionUtils::getReflectDesc($o));

        $o = new class() implements Reflector {
            public static function export()
            {
            }
            public function __toString()
            {
                return "ddcc";
            }
        };
        self::assertEquals("ddcc", ReflectionUtils::getReflectDesc($o));
    }
}

# end of file
